Mendel Config
This is an internal package that helps Mendel normalize configuration defaults, on .mendelrc
or on package.json
. It is used by many Mendel packages to make sure all packages use the same defaults and same merging logic.
API
var configParser = require('mendel-config');
var config = configParser();
var config = configParser('./sub/folder/config');
var config = configParser({ basedir: './sub/folder/config' });
var config = configParser({
config: false,
});
var config = configParser({
});
Configuration parsing happens in 3 steps:
1. Merging by precedence:
Configuration precedence is, from order to strongest to weakest:
- Passing configuration as an JavaScript object
- Configuration on
.mendelrc
or package.json
- Mendel defaults
The only exception is basedir
. basedir
has different meanings depending on where you declare it:
- If
basedir
is passed programmatically it is meant as a configuration lookup folder - If any of
.mendelrc
or package.json
is found, basedir is forced to be the folder that contains the config file, even if you provide one as property of the configuration object. - All other path entries that are not absolute will be relative to
basedir
2. Merging by environment
Either process.env.MENDEL_ENV
or process.env.NODE_ENV
values can be used to configure overrides on .mendelrc
.
3. Resolving relative paths
After parsing and merging all the configurations a number of path properties will be resolved relative to basedir or their "parent" configuration, for example bundlesoutdir
is relative to outdir
which is in place relative to basedir
. Please refer to .mendelrc
file configuration documentation to a full list.
4. Parsing bundles
In .mendelrc
or package.json
the bundles entry is an object, we will transform bundles into an array and lastly the following arrays will be flattened: entries
, require
, external
, exclude
, ignore
.
Flattening is useful to use YAML references to manipulate the file lists. For example, the logged_in_bundle
bellow will have all files from vendor
and from main
, since arrays are flattened:
build-dir: ./build
base-config:
id: base
dir: ./src/master
variation-config:
variation-dirs:
- ./src/environments
- ./src/settings
- ./src/experiments
- ./src/themes
variations:
button_color:
- blue_button
route-config:
variation: /mendel/:variations/:bundle
hash: /mendel/:hash/:bundle
transforms:
babelify-dev:
plugin: mendel-babelify
options:
plugins:
-
- react-intl
- messagesDir: ./tmp/strings/
enforceDescriptions: true
babelify-prod:
plugin: mendel-babelify
options:
plugins:
- react-intl-remove-description
- transform-react-remove-prop-types
-
- react-intl
- messagesDir: ./tmp/strings/
enforceDescriptions: true
custom-transform:
plugin: ./transforms/custom.js
envify-dev:
options:
NODE_ENV: development
envify-prod:
options:
NODE_ENV: production
minify:
plugin: mendel-uglify-js
coverage:
plugin: mendel-istanbul
post-css:
plugin: mendel-post-css
options:
foo: bar
types:
css:
transforms:
- post-css
outlet:
plugin: mendel-css-pack
javascript:
outlet:
plugin: mendel-bundle-browser-pack
transforms:
- envify-dev
- babelify-dev
extensions:
- .js
- .json
- .jsx
node_modules:
transforms:
- envify-dev
env:
production:
types:
javascript:
outlet:
plugin: mendel-bundle-rollup
transforms:
- envify-prod
- babelify-dev
- minify
node_modules:
- envify-prod
- minify
unit-test:
types:
javascript:
transforms:
- envify-dev
- babelify-dev
- coverage
generators:
- id: extract-bundles
plugin: mendel-extract-bundles
- id: node-modules-generator
plugin: mendel-extract-node-modules
bundles:
main:
outfile: app.js
entries:
- /apps/main
lazy-group-1:
outfile: lazy1.js
generator: extract-bundles
from: main
extract-entries:
- /apps/lazy
deps:
outfile: vendor.js
generator: node-modules-generator
all-bundles: true
css:
outfile: app.css
generator: atomic-css-generator
entries:
- /apps/main